package com.systemic.controller;

import com.systemic.core.ResponseResult;
import com.systemic.pojo.*;
import com.systemic.service.*;
import com.systemic.vo.PageVo;
import com.systemic.vo.SearchUser;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName: MindfulnessGroupController
 * @Description:
 * @Author:
 * @CreateTime: 2024-02-02 10:05
 * @Version:
 **/
@RestController
@RequestMapping("/group")
public class MindfulnessGroupController {

    @Resource
    private GroupCreateApplyService groupCreateApplyService;

    /**
     * 团队创建申请
     * @param groupCreateApply
     * @return
     */
    @PostMapping("/apply")
    public ResponseResult<String> createApply(@RequestBody GroupCreateApply groupCreateApply){
        int row = groupCreateApplyService.createApply(groupCreateApply);
        return row!=0 ? ResponseResult.success("新增成功") : ResponseResult.failed("新增失败");
    }

    /**
     * 审批列表（管理端）
     * @param pageVo
     * @return
     */
    @PostMapping("/audit")
    public ResponseResult<List<GroupCreateApply>> audit(@RequestBody PageVo pageVo){
        List<GroupCreateApply> res = groupCreateApplyService.selectList(pageVo);
        return !res.isEmpty() ? ResponseResult.success(res) : ResponseResult.failed("没有内容");
    }

    /**
     * 审批通过（管理端）
     * @param id
     * @return
     */
    @GetMapping("/agree/{id}")
    public ResponseResult<String> agree(@PathVariable("id")Integer id){
        int row = groupCreateApplyService.agree(id);
        return row!=0 ? ResponseResult.success("成功") : ResponseResult.failed("失败");
    }

    /**
     * 审批忽略（管理端）
     * @param id
     * @return
     */
    @GetMapping("/disagree/{id}")
    public ResponseResult<String> disagree(@PathVariable("id")Integer id){
        int row = groupCreateApplyService.disagree(id);
        return row!=0 ? ResponseResult.success("成功") : ResponseResult.failed("失败");
    }

    @Resource
    private GroupInfoService groupInfoService;

    /**
     * 团体列表
     * @param pageVo
     * @return
     */
    @PostMapping("/selectList")
    public ResponseResult<List<GroupInfo>> selectList(@RequestBody PageVo pageVo){
        List<GroupInfo> res = groupInfoService.selectList(pageVo);
        return !res.isEmpty() ? ResponseResult.success(res) : ResponseResult.failed("失败");
    }


    /**
     * 修改团体信息
     * @param groupInfo
     * @return
     */
    @PostMapping("/update")
    public ResponseResult<String> update(@RequestBody GroupInfo groupInfo){
        int row = groupInfoService.update(groupInfo);
        return row!=0 ? ResponseResult.success("成功") : ResponseResult.failed("失败");
    }

    /**
     * 注销团体
     * @param id
     * @return
     */
    @GetMapping("/logoff/{id}")
    public ResponseResult<String> logoff(@PathVariable("id")Integer id){
        int row = groupInfoService.logoff(id);
        return row!=0 ? ResponseResult.success("成功") : ResponseResult.failed("失败");
    }

    @Resource
    private GroupJoinApplyService groupJoinApplyService;

    /**
     * 加入申请
     * @param groupJoinApply
     * @return
     */
    @PostMapping("/joinApply")
    public ResponseResult<String> joinApply(@RequestBody GroupJoinApply groupJoinApply){
        int row = groupJoinApplyService.joinApply(groupJoinApply);
        return row!=0 ? ResponseResult.success("成功") : ResponseResult.failed("失败");
    }

    /**
     * 查看加入申请
     * @param pageVo
     * @return
     */
    @PostMapping("/joinApplyList")
    public ResponseResult<List<GroupJoinApply>> joinApplyList(@RequestBody PageVo pageVo){
        List<GroupJoinApply> res = groupJoinApplyService.selectListById(pageVo);
        return !res.isEmpty() ? ResponseResult.success(res) : ResponseResult.failed("没有内容");
    }

    /**
     * 同意加入申请
     * @param groupJoinApply
     * @return
     */
    @PostMapping("/joinAgree")
    public ResponseResult<String> joinAgree(@RequestBody GroupJoinApply groupJoinApply){
        int row = groupJoinApplyService.joinAgree(groupJoinApply);
        return row!=0 ? ResponseResult.success("成功") : ResponseResult.failed("失败");
    }

    /**
     * 忽略加入申请
     * @param groupJoinApply
     * @return
     */
    @PostMapping("/joinDisagree")
    public ResponseResult<String> joinDisagree(@RequestBody GroupJoinApply groupJoinApply){
        int row = groupJoinApplyService.joinDisagree(groupJoinApply);
        return row!=0 ? ResponseResult.success("成功") : ResponseResult.failed("失败");
    }

    @Resource
    private GroupMindfulnessInfoService groupMindfulnessInfoService;

    /**
     * 发起活动
     * @param groupMindfulnessInfo
     * @return
     */
    @PostMapping("/mindfulness")
    public ResponseResult<String> addMindfulness(@RequestBody GroupMindfulnessInfo groupMindfulnessInfo){
        int row = groupMindfulnessInfoService.addMindfulness(groupMindfulnessInfo);
        return row!=0 ? ResponseResult.success("成功") : ResponseResult.failed("失败");
    }

    /**
     * 查看活动列表
     * @param pageVo
     * @return
     */
    @PostMapping("/mindfulnessList")
    public ResponseResult<List<GroupMindfulnessInfo>> mindfulnessList(@RequestBody PageVo pageVo){
        List<GroupMindfulnessInfo> res = groupMindfulnessInfoService.mindfulnessList(pageVo);
        return !res.isEmpty() ? ResponseResult.success(res) : ResponseResult.failed("没有内容");
    }

    /**
     * 查看活动信息
     * @param id
     * @return
     */
    @GetMapping("/mindfulnessInfo/{id}")
    public ResponseResult<GroupMindfulnessInfo> mindfulnessInfo(@PathVariable("id")Integer id){
        GroupMindfulnessInfo res = groupMindfulnessInfoService.mindfulnessInfo(id);
        return res!=null ? ResponseResult.success(res) : ResponseResult.failed("失败");
    }

    /**
     * 修改活动
     * @param groupMindfulnessInfo
     * @return
     */
    @PostMapping("/mindfulnessInfoUpdate")
    public ResponseResult<String> mindfulnessInfoUpdate(@RequestBody GroupMindfulnessInfo groupMindfulnessInfo){
        int row = groupMindfulnessInfoService.mindfulnessInfoUpdate(groupMindfulnessInfo);
        return row!=0 ? ResponseResult.success("成功") : ResponseResult.failed("失败");
    }

    /**
     * 删除活动
     * @param id
     * @return
     */
    @GetMapping("/mindfulnessDelete/{id}")
    public ResponseResult<String> mindfulnessDelete(@PathVariable("id")Integer id){
        int row = groupMindfulnessInfoService.mindfulnessDelete(id);
        return row!=0 ? ResponseResult.success("成功") : ResponseResult.failed("失败");
    }

    @Resource
    private GroupLogService groupLogService;

    /**
     * 练习打卡新增
     * @param groupLog
     * @return
     */
    @PostMapping("/clockInAdd")
    public ResponseResult<String> clockInAdd(@RequestBody GroupLog groupLog){
        int row = groupLogService.clockInAdd(groupLog);
        return row!=0 ? ResponseResult.success("成功") : ResponseResult.failed("失败");
    }

    /**
     * 练习打卡查看
     * @param pageVo
     * @return
     */
    @PostMapping("/clockIn")
    public ResponseResult<List<GroupLog>> clockIn(@RequestBody PageVo pageVo){
        List<GroupLog> res = groupLogService.clockIn(pageVo);
        return !res.isEmpty() ? ResponseResult.success(res) : ResponseResult.failed("没有内容");
    }

    /**
     * 练习打卡删除
     * @param id
     * @return
     */
    @GetMapping("/clockInDelete/{id}")
    public ResponseResult<String> clockInDelete(@PathVariable("id")Integer id){
        int row = groupLogService.clockInDelete(id);
        return row!=0 ? ResponseResult.success("成功") : ResponseResult.failed("失败");
    }

    @Resource
    private GroupRelationService groupRelationService;

    /**
     * 查看已加入的团体
     * @param pageVo
     * @return
     */
    @PostMapping("/relationJoin")
    public ResponseResult<List<GroupInfo>> relationJoin(@RequestBody PageVo pageVo){
        List<GroupInfo> res = groupRelationService.relationJoin(pageVo);
        return !res.isEmpty() ? ResponseResult.success(res) : ResponseResult.failed("没有内容");
    }

    /**
     * 成员列表
     * @param pageVo
     * @return
     */
    @PostMapping("/relationList")
    public ResponseResult<List<SearchUser>> relationList(@RequestBody PageVo pageVo){
        List<SearchUser> res = groupRelationService.relationList(pageVo);
        return !res.isEmpty() ? ResponseResult.success(res) : ResponseResult.failed("没有内容");
    }

    /**
     * 退出团体
     * @param groupRelation
     * @return
     */
    @PostMapping("/relationDelete")
    public ResponseResult<String> relationDelete(@RequestBody GroupRelation groupRelation){
        int row = groupRelationService.relationDelete(groupRelation);
        return row!=0 ? ResponseResult.success("成功") : ResponseResult.failed("失败");
    }






}
